<template>
  <span 
    :class="[
      'bx-tag',
      'bx-glass',
      `bx-tag--${variant}`,
      `bx-tag--${size}`,
      {
        'bx-tag--closable': closable,
        'bx-tag--checkable': checkable,
        'bx-tag--checked': checkable && checked
      }
    ]"
    @click="handleClick"
  >
    <BxIcon v-if="icon" :name="icon" class="bx-tag__icon" />
    <span class="bx-tag__content">
      <slot>{{ content }}</slot>
    </span>
    <BxIcon 
      v-if="closable"
      name="close"
      class="bx-tag__close"
      @click.stop="handleClose"
    />
  </span>
</template>

<script>
import { ref } from 'vue'
import BxIcon from '../basic/BxIcon.vue'

export default {
  name: 'BxTag',
  components: {
    BxIcon
  },
  props: {
    content: {
      type: String,
      default: ''
    },
    variant: {
      type: String,
      default: 'default',
      validator: (value) => ['default', 'primary', 'success', 'warning', 'danger', 'info'].includes(value)
    },
    size: {
      type: String,
      default: 'medium',
      validator: (value) => ['small', 'medium', 'large'].includes(value)
    },
    closable: {
      type: Boolean,
      default: false
    },
    checkable: {
      type: Boolean,
      default: false
    },
    checked: {
      type: Boolean,
      default: false
    },
    icon: {
      type: String,
      default: ''
    }
  },
  emits: ['close', 'click', 'check'],
  setup(props, { emit }) {
    const isChecked = ref(props.checked)

    const handleClick = (event) => {
      if (props.checkable) {
        isChecked.value = !isChecked.value
        emit('check', isChecked.value, event)
      }
      emit('click', event)
    }

    const handleClose = (event) => {
      emit('close', event)
    }

    return {
      isChecked,
      handleClick,
      handleClose
    }
  }
}
</script>

<style scoped>
.bx-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--bx-spacing-xs);
  padding: 4px 8px;
  border: 1px solid var(--bx-glass-border);
  border-radius: var(--bx-radius-medium);
  background: var(--bx-glass-bg);
  backdrop-filter: var(--bx-glass-blur);
  color: var(--bx-text-primary);
  font-family: var(--bx-font-family);
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
  transition: all var(--bx-transition-medium);
  cursor: default;
  user-select: none;
}

.bx-tag:hover {
  border-color: var(--bx-glass-border-hover);
  background: var(--bx-glass-bg-hover);
}

/* 尺寸变体 */
.bx-tag--small {
  padding: 2px 6px;
  font-size: 11px;
  border-radius: var(--bx-radius-small);
}

.bx-tag--medium {
  padding: 4px 8px;
  font-size: 12px;
}

.bx-tag--large {
  padding: 6px 12px;
  font-size: 14px;
}

/* 颜色变体 */
.bx-tag--primary {
  background: var(--bx-primary);
  border-color: rgba(0, 122, 255, 0.4);
  color: var(--bx-text-primary);
}

.bx-tag--success {
  background: var(--bx-success);
  border-color: rgba(52, 199, 89, 0.4);
  color: var(--bx-text-primary);
}

.bx-tag--warning {
  background: var(--bx-warning);
  border-color: rgba(255, 149, 0, 0.4);
  color: var(--bx-text-primary);
}

.bx-tag--danger {
  background: var(--bx-danger);
  border-color: rgba(255, 59, 48, 0.4);
  color: var(--bx-text-primary);
}

.bx-tag--info {
  background: rgba(142, 142, 147, 0.25);
  border-color: rgba(142, 142, 147, 0.4);
  color: var(--bx-text-primary);
}

/* 可点击状态 */
.bx-tag--checkable {
  cursor: pointer;
}

.bx-tag--checkable:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.bx-tag--checked {
  background: rgba(0, 122, 255, 0.35);
  border-color: rgba(0, 122, 255, 0.6);
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.2);
}

/* 可关闭状态 */
.bx-tag--closable {
  padding-right: 4px;
}

.bx-tag__icon {
  font-size: 1em;
}

.bx-tag__content {
  flex: 1;
}

.bx-tag__close {
  font-size: 10px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity var(--bx-transition-medium);
  margin-left: 2px;
}

.bx-tag__close:hover {
  opacity: 1;
}

/* 渐变效果 */
.bx-tag::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(255, 255, 255, 0.05) 100%
  );
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--bx-transition-medium);
}

.bx-tag:hover::before {
  opacity: 1;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .bx-tag--small {
    padding: 1px 4px;
    font-size: 10px;
  }
  
  .bx-tag--medium {
    padding: 3px 6px;
    font-size: 11px;
  }
  
  .bx-tag--large {
    padding: 5px 10px;
    font-size: 13px;
  }
  
  .bx-tag__close {
    font-size: 9px;
  }
}
</style>

